package ru.study.thinkin.chapter12;

import java.io.*;

public class InputFile {
	private BufferedReader in;
	public InputFile(String fname)  throws Exception {
		try {
			in = new BufferedReader(new FileReader(fname));
			//Thread.sleep(10000);
		} catch (FileNotFoundException e) {
			System.out.println("Невозможео открыть файл" + fname);			
			throw e;
			
		} catch (Exception e) {		
			e.printStackTrace();				
			try {
				in.close();
			} catch (IOException e2) {
				System.out.println("Input File close() неудачно");
			}
			
			throw e;
			
		} finally {
			//не закрывать файл
		}
	}
	public String getLine() {
		String s;
		try {
			s = in.readLine();
		} catch (IOException e) {
			throw  new RuntimeException("readLine() исполнение неудачно");
		}
		return s;
	}
	public void dispose() {
		try {
			in.close();
			System.out.println("dispose() успешен");
		} catch (IOException e2) {
			throw new RuntimeException("dispose close() неудачно");
		}
	}
	
	public static void main(String[] args) {
		try { 
			InputFile in = new InputFile("C:/QWERTY.txt");
			try {
				String s;
				int i =1;
				while((s=in.getLine())!=null) {
					System.out.println(s);
				}
			} catch (Exception e) {				
				System.out.println("перехвачен Exception в main "+e.getClass());
				e.printStackTrace();			
			}
			finally {
				in.dispose();
			}
		} catch (Exception e) {					
			System.out.println("Cбой создания InputFile");
			e.printStackTrace();			
		} 

	}

}
